package com.weigee.ktv.v.adapter.rv;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.l.d.app.library.eventbus.EventSend;
import com.l.d.app.library.adapter.RvListAdapter;
import com.weigee.ktv.R;
import com.weigee.ktv.m.EventTag;
import com.weigee.ktv.m.entity.WrapHolder;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import skin.support.widget.SkinCompatTextView;

/**
 * Created by linde on 2017/4/18.
 * <p/>
 */

public class CheckRoomNeedAdapter extends RvListAdapter<String, CheckRoomNeedAdapter.Holder> {
    @NonNull
    @Override
    public List<String> onCreateNewEmptyList() {
        return new ArrayList<>();
    }

    @Override
    public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
        final Context context = parent.getContext();
        final View itemView = LayoutInflater.from(context).inflate(R.layout.dialog_check_reserve_room_rv_item, parent, false);
        return new Holder(itemView);
    }

    @Override
    public void onBindViewHolder(final Holder holder, int position) {
        final String roomData = getItem(position);
        if (TextUtils.isEmpty(roomData)) {
            holder.itemView.setVisibility(View.GONE);
        } else {
            holder.itemView.setVisibility(View.VISIBLE);
            holder.tvRoomMsg.setText(roomData);
            holder.tvRoomMsg.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    EventSend.with(EventTag.EVENT_CHECK_RESERVE_ROOM_RETURN)
                            .msg(roomData)
                            .build();
                }
            });
        }
    }

    static class Holder extends WrapHolder {
        @BindView(R.id.tv_room_msg)
        SkinCompatTextView tvRoomMsg;

        private Holder(View itemView) {
            super(itemView);
        }
    }
}
